package com.chen.manager.controller;

import com.chen.log.annotation.Log;
import com.chen.manager.service.BrandService;
import com.chen.model.entity.product.Brand;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cgj
 * @date 3/4/25 3:25 PM
 */
@RestController
@RequestMapping("/admin/product/brand")

public class BrandController {
    @Autowired
    private BrandService brandService;
    /**
     * 根据分类查询所有的品牌
     */
//    @Log
    @GetMapping("/selectBrandByCategoryId/{categoryId}")
    public Result<List<Brand>> selectBrandByCategoryId(@PathVariable Long categoryId){
        List<Brand> brandList=brandService.selectBrandByCategoryId(categoryId);
        return Result.build(brandList,ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询所有品牌
     * @return
     */
    @GetMapping("/findAll")
    public Result<List<Brand>> findAll(){
        List<Brand> brandList=brandService.findAll();
        return Result.build(brandList,ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/deleteBrandById/{id}")
    public Result deleteBrandById(@PathVariable Long id){
        brandService.deleteBrandById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 修改品牌
     * @param brand
     * @return
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody Brand brand){
        brandService.edit(brand);
        return  Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 新增品牌
     *
     */
    @PostMapping("/save")
    public Result sava(@RequestBody Brand brand){
        brandService.save(brand);
        return  Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 分页查询
     */
//    @Log(title = "brand",businessType = 0)
    @GetMapping("/showByPage/{pageNum}/{PageSize}")
    public Result<PageInfo<Brand>> showByPage(@PathVariable Integer pageNum,
                                              @PathVariable Integer PageSize){
//        System.out.println(1/0);
          PageInfo<Brand> pageInfo=brandService.showByPage(pageNum,PageSize);

        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
}
